package Classes.GameUtils
{
	import flash.display.SpreadMethod;
	import flash.display.Sprite;
	import flash.filters.BlurFilter;
	import flash.system.ApplicationDomain;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;

	public class MyTipSprite extends BaseTipSprite
	{
		private var tipBgClass:Class;
		public function MyTipSprite(data:*, delayInit:Boolean=true)
		{
			super(data, delayInit);
			tipBgClass=ApplicationDomain.currentDomain.getDefinition("TutorialToolTipAsset") as Class;	
//			tipBgClass=ApplicationDomain.currentDomain.getDefinition("toolTipNew_v") as Class;
		}	
		private var _t:TextField;
		private var _tt:TextField;				//标题
		private var _tipBg:Sprite;				//底板UI
		private var jj:uint=22;				//y间距
		private var tbg:Sprite;
		override protected function buildUI(data:*):void
		{
			tbg=new Sprite;
			tbg= new (ApplicationDomain.currentDomain.getDefinition("tipTbg") as Class);
			
			_tt=new TextField();
			_t=new TextField();
			_t.autoSize=TextFieldAutoSize.LEFT;
			_t.wordWrap=true;
			_tt.autoSize=TextFieldAutoSize.LEFT;
			_t.x = 2;
			
			if(String(data).indexOf("<")==-1)
			{
				if(String(data).length<8)
					_t.width=50;
				
				var ary:Array	=	String(data).split("：");
				if(ary.length<2)ary	=	String(data).split(":");
				
				_tt.htmlText	=	ary[0];
				
				if(ary.length>1){
					var st:String	= ary[1];
					for(var i:uint=2; i<ary.length; i++)
						st+= ":"+ary[i];
					_t.htmlText	=	st;
				}
				
				_t.y = tbg.y		=   jj;
				tbg.height	=	_t.height-2;
     			if(ary.length>1){
					this.addChild(tbg);
					tbg.width	=	_t.width;
					
				}
				this.addChild(_tt);
				this.addChild(_t);
				_tt.height	=	jj;
				
			}
			else{
				_t.htmlText	= String(data);
				this.addChild(_t);
			}
		}
		
		override public function setTextFieldTxt(txt:String):void
		{
			if(this._t)
			{
				this._t.htmlText=txt;
			}
		}
		
		
		/**
		 *在热感加好之后，重设置标题 
		 * 子类需重写
		 * @param txt
		 * 
		 */
		override public function setTitleText(txt:String):void
		{
			if(this._tt)
			{
				this._tt.htmlText=txt;
			}
		}
		
		
		override public function get skinClass():Class
		{
			return tipBgClass;
		}
		
		/**
		 *跟据ui设置文本的样式，和底板样式 
		 * @param value
		 * 
		 */
		override public function set tipBg(value:Sprite):void
		{
			this._tipBg	=	value;
			_tt.setTextFormat((value.getChildByName("ttformat") as TextField).getTextFormat() );
			_tt.filters	=	(value.getChildByName("ttformat") as TextField).filters;
			if(String(data).indexOf("<")==-1)
			{
				_t.setTextFormat((value.getChildByName("tformat") as TextField).getTextFormat() );
				_t.filters	=	(value.getChildByName("tformat") as TextField).filters;
			}
			
			if(_t.width-1<_tt.width){_t.width=_tt.width-2;tbg.width=_t.width-2;}
			
			tbg.width+=2;
			this._tipBg.width+=2;
			
		}
	}
}